﻿using System.Collections.Generic;
using AcountingService.DataTransferObjects.Voucher;
using BusinessObjects.BussinessVoucher;
using System.Linq;

namespace AcountingService.DataTransferObjectMapper.Voucher  
{
    /// <summary>
    /// 
    /// </summary>
    public static class Mapper
    {
        #region ToDataTransferObjects

        /// <summary>to
        /// To the data transfer objects.
        /// </summary>
        /// <param name="c">The c.</param>
        /// <returns></returns>
        public static IList<ItemTransactionDto> ToDataTransferObjects(IEnumerable<ItemTransaction> c)
        {
            return c == null ? null : c.Select(source => ToDataTransferObject((source))).ToList();
        }

        /// <summary>to
        /// To the data transfer objects.
        /// </summary>
        /// <param name="c">The c.</param>
        /// <returns></returns>
        public static IList<ItemTransactionDetailDto> ToDataTransferObjects(IEnumerable<ItemTransactionDetail> c)
        {
            return c == null ? null : c.Select(source => ToDataTransferObject((source))).ToList();
        }
       #endregion

        #region ToDataTransferObject.

        /// <summary>
        /// Froms the data transfer object.
        /// </summary>
        /// <param name="c">The c.</param>
        /// <returns></returns>
        public static ItemTransactionDto ToDataTransferObject(ItemTransaction c)
        {
            if (c == null) return null;

            return new ItemTransactionDto
                {
                    RefId = c.RefId,
                    RefTypeId = c.RefTypeId,
                    RefNo = c.RefNo,
                    RefDate = c.RefDate,
                    UnitId = c.UnitId,
                    TaxCode = c.TaxCode,
                    CustomerId = c.CustomerId,
                    VendorId = c.VendorId,
                    TotalAmountTax = c.TotalAmountTax,
                    Trader = c.Trader,
                    StockId = c.StockId,
                    TotalAmountOc = c.TotalAmountOc,
                    JournalMemo = c.JournalMemo,
                    DocumentInclude = c.DocumentInclude,
                    AccountingObjectType = c.AccountingObjectType,
                    IsCalculatePrice = c.IsCalculatePrice,
                //    ItemTransactionDetails = c.ItemTransactionDetails == null ? null : ToDataTransferObjects(c.ItemTransactionDetails)
                };
        }

        /// <summary>
        /// Froms the data transfer object.
        /// </summary>
        /// <param name="c">The c.</param>
        /// <returns></returns>
        public static ItemTransactionDetailDto ToDataTransferObject(ItemTransactionDetail c)
        {
            if (c == null) return null;
            return new ItemTransactionDetailDto
                {
                    ItemTransactionDetailId = c.ItemTransactionDetailId,
                    InventoryItemId = c.InventoryItemId,
                    AccountNumber = c.AccountNumber,
                    CorrespondingAccountNumber = c.CorrespondingAccountNumber,
                    Description = c.Description,
                    AmountOc = c.AmountOc,
                    AmountVat = c.AmountVat,
                    AccountNumberVat = c.AccountNumberVat,
                    TaxRate = c.TaxRate,
                    RefId = c.RefId,
                    Quantity = c.Quantity,
                    Price = c.Price,
                    VoucherTypeId = c.VoucherTypeId,

                };
        }

        #endregion

        #region FromDataTransferObject

        /// <summary>
        /// 
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        public static ItemTransaction FromDataTransferObject(ItemTransactionDto c)
        {
            if (c == null) return null;

            return new ItemTransaction
                {
                    RefId = c.RefId,
                    RefTypeId = c.RefTypeId,
                    RefNo = c.RefNo,
                    RefDate = c.RefDate,
                    UnitId = c.UnitId,
                    TaxCode = c.TaxCode,
                    CustomerId = c.CustomerId,
                    VendorId = c.VendorId,
                    TotalAmountTax = c.TotalAmountTax,
                    Trader = c.Trader,
                    StockId = c.StockId,
                    TotalAmountOc = c.TotalAmountOc,
                    JournalMemo = c.JournalMemo,
                    DocumentInclude = c.DocumentInclude,
                    AccountingObjectType = c.AccountingObjectType,
                    IsCalculatePrice = c.IsCalculatePrice,
               //     ItemTransactionDetails = c.ItemTransactionDetails == null ? null : FromDataTransferObjects(c.ItemTransactionDetails)
                };
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        public static ItemTransactionDetail FromDataTransferObject(ItemTransactionDetailDto c)
        {
            if (c == null) return null;

            return new ItemTransactionDetail
                {
                    ItemTransactionDetailId = c.ItemTransactionDetailId,
                    InventoryItemId = c.InventoryItemId,
                    AccountNumber = c.AccountNumber,
                    CorrespondingAccountNumber = c.CorrespondingAccountNumber,
                    Description = c.Description,
                    AmountOc = c.AmountOc,
                    AmountVat = c.AmountVat,
                    AccountNumberVat = c.AccountNumberVat,
                    TaxRate = c.TaxRate,
                    RefId = c.RefId,
                    Quantity = c.Quantity,
                    Price = c.Price,
                    VoucherTypeId = c.VoucherTypeId,
                };
        }

        #endregion

        #region FromDataTransferObjects

        /// <summary>
        /// Froms the data transfer objects.
        /// </summary>
        /// <param name="c">The c.</param>
        /// <returns></returns>
        public static IList<ItemTransaction> FromDataTransferObjects(IEnumerable<ItemTransactionDto> c)
        {
            return c == null ? null : c.Select(source => FromDataTransferObject((source))).ToList();
        }

        /// <summary>
        /// Froms the data transfer objects.
        /// </summary>
        /// <param name="c">The c.</param>
        /// <returns></returns>
        public static IList<ItemTransactionDetail> FromDataTransferObjects(IEnumerable<ItemTransactionDetailDto> c)
        {
            return c == null ? null : c.Select(source => FromDataTransferObject((source))).ToList();
        }

        #endregion
    }
}
